﻿/*
 * Created by SharpDevelop.
 * User: rogerio
 * Date: 11/03/2010
 * Time: 10:13
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Collections.Generic;

namespace csharp.rad.general
{
	/// <summary>
	/// Description of Stock.
	/// </summary>
	public class Stock : csharp.common.DefaultClass, csharp.common.IClass
	{
		#region Variables
			private string _warehouse_id;
			private string _product_id;
			private string _user_id;
			private string _date;
			private string _hour;
			private string _atual_value;
		#endregion
		
		public Stock()
		{
			gsql.table = "common.stock";
			_sequence  = "common.stock_stock_id_seq";
			
			clear();
		}
		
		#region Gets and Sets	
			public string warehouse_id {
				get { return _warehouse_id; }
				set { _warehouse_id = value; }
			}
			
			public string product_id {
				get { return _product_id; }
				set { _product_id = value; }
			}
			
			public string user_id {
				get { return _user_id; }
				set { _user_id = value; }
			}
			
			public string date {
				get { return _date; }
				set { _date = value; }
			}
			
			public string hour {
				get { return _hour; }
				set { _hour = value; }
			}
			
			public string atual_value {
				get { return _atual_value; }
				set { _atual_value = value; }
			}			
		#endregion
		
		#region Declarations methods
			public override bool delete()
			{
				return base.delete();
			}
			
			public override void get(System.Data.DataRow dr)
			{
				_id				= dr["stock_id"].ToString();
				_warehouse_id	= dr["stock_warehouse_id"].ToString();
				_product_id		= dr["stock_product_id"].ToString();	
				_user_id		= dr["stock_user_id"].ToString();
				_date			= Convert.ToDateTime(dr["stock_date"]).ToString("dd/MM/yyyy");
				_hour			= dr["stock_hour"].ToString();
				_atual_value	= dr["stock_atual_value"].ToString();
			}
			
			public override bool save()
			{
				return base.save();
			}
			
			public override void setGsql()
			{
				gsql.setValue( _id           			  	, "stock_id");
				gsql.setValue( _warehouse_id				, "stock_warehouse_id");
				gsql.setValue( _product_id					, "stock_product_id");	
				gsql.setValue( _user_id						, "stock_user_id");
				gsql.setValue( _date						, "stock_date");
				gsql.setValue( _hour						, "stock_hour");
				gsql.setValue( _atual_value					, "stock_atual_value");
			}
			
			public override bool store(csharp.common.GenerateSql.TCommandType ctype)
			{
				return base.store(ctype);
			}
			
			public override bool update()
			{
				return base.update();
			}
			
			public void clear()
			{
				_id				= String.Empty;
				_warehouse_id	= String.Empty;
				_product_id		= String.Empty;	
				_user_id		= String.Empty;
				_date			= String.Empty;
				_hour			= String.Empty;
				_atual_value	= String.Empty;
			}
		#endregion
	}
	
	public class Stocks : csharp.common.DefaultList, csharp.common.IList
	{		
		public Stocks()
		{
			gsql.table = "common.stock";
			clear();
		}
		
		#region Declarations methodos
			public Stock get()
			{
				return (Stock)items[index];
			}
			
			public Stock get(Int32 index)
			{
				return (Stock)items[index];
			}
			
			public bool fillList()
			{
				gsql.prepare();
				
				gsql.setValue("", "*");		
				//gsql.conditionalWhere = "stock_company_id = "+Information.companyId;
				
				return mountList();
			}
			
			public bool mountList()
			{
				int tam;
				if(!gsql.execute())
				{
					return false;
				}
				
				tam = gsql.getRowCount();
				items.Clear();
				
				for(int i = 0; i < tam; i++)
				{
					Stock s = new Stock();
					s.get(gsql.getRow(i));
					items.Add(s);
				}
				return true;
			}
		#endregion
	}
}
